package com.notepad.adapter;

import java.util.ArrayList;

import com.notepad.R;
import com.notepad.domain.DrawerMenuEntity;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MenuListAdapter extends BaseAdapter {
	private LayoutInflater mLayoutInflater;
	private ArrayList<DrawerMenuEntity> mList;
	public MenuListAdapter(Context context, ArrayList<DrawerMenuEntity> data) {
		mLayoutInflater = LayoutInflater.from(context);
		mList = data;
	}

	@Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if(convertView == null){
			holder = new ViewHolder();
			convertView = mLayoutInflater.inflate(R.layout.main_menu_items,null);
			holder.icon = (ImageView) convertView.findViewById(R.id.menu_icon);
			holder.title = (TextView) convertView.findViewById(R.id.menu_title);
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder) convertView.getTag();
		}
		holder.icon.setImageResource(mList.get(position).getMenu_icon());
		holder.title.setText(mList.get(position).getMenu_title());
		return convertView;
	}
	private static class ViewHolder{
		private ImageView icon;
		private TextView title;
	} 

}
